package com.uikoo9.manage.y.controller;

import com.uikoo9.manage.y.model.YDemoModel;
import com.uikoo9.manage.y.util.StringUtil;
import com.uikoo9.plugin.QTree1;
import com.uikoo9.util.core.annotation.QControllerUrl;
import com.uikoo9.util.jfinal.QController;
import com.uikoo9.util.plugin.json.QJsonUtil;
import com.uikoo9.util.plugin.tree.QTree;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * YDemoController
 * @author qiaowenbin
 */
@QControllerUrl("/y/demo")
public class YDemoController extends QController{
	
	/**
	 * 跳转到首页 
	 */
	public void index(){
		setAttr("qpage", list(YDemoModel.class));

        List<Map> listmymenus  = new ArrayList<Map>();
        for(int i=0;i<2;i++){
            Map a =new HashMap();
            a.put("ucenter_menu_url","#");
            a.put("ucenter_menu_title","菜单"+i);
            listmymenus.add(a);
        }
        setAttr("mymenus", listmymenus);

        List<Map> listmyul  = new ArrayList<Map>();
        for(int i=0;i<4;i++){
            Map a =new HashMap();
            a.put("text","事项"+i);
            a.put("id","id"+i);
            listmyul.add(a);
        }
        setAttr("listmyul", listmyul);

        setAttr("mypics", "bg/bg1.jpg");//

        List<Map> blogTypes  = new ArrayList<Map>();
        String list = " 菜单-bsmenu,图片轮播-bslun,略缩图-bsnail, 按钮-bsbutton, 输入框-bsinput," +
                " icon-bsicon, 进度条-bspro, bsalert, bsul, bspanel, bdshare, curd,bstree";
        for(String s:list.split(",")){
            Map a =new HashMap();
            String _id = "";
            String _name ="";
            if(s.contains("-")){
                _id = s.split("-")[1].trim();
                _name = s.split("-")[0].trim();
            }else {
                _name = s.trim();
                _id = _name;
            }
            a.put("id", _id);
            a.put("blog_type_name", _name);
            blogTypes.add(a);
        }
        setAttr("blogTypes", blogTypes);

        List<Map> spy  = new ArrayList<Map>();
        for(int i=0;i<5;i++){
            Map a =new HashMap();
            String id =i+"";
            switch (i){
                case 0:id="bstabs";break;
                case 1:id="bslun";break;
                case 3:id="bsicon";break;
                case 5:id="bdshare";break;
            }
            a.put("id",id);
            a.put("text","菜单"+id);
            spy.add(a);
        }
        //bsmenu 菜单 图片轮播bslun 略缩图bsnail 按钮bsbutton 输入框bsinput iconbsicon 进度条 bspro  bsalert
        setAttr("spy", spy);
        List<Map> l = new ArrayList<Map>();
        for(int i=1;i<=5;i++){
            Map a =new HashMap();
            String id =i+"";
            a.put("id",id);
            a.put("pid",--i+"");
            a.put("text","菜单"+id);
            a.put("url","/"+id);
            l.add(a);
            i++;
        }
        setAttr("tree", new QTree1(0, "/", "根菜单",l, null));

        List<Map> ltabs = new ArrayList<Map>();
        for(int i=1;i<=5;i++){
            Map a =new HashMap();
            String id =i+"";
            a.put("id",id);
            a.put("text","菜单"+id);
            ltabs.add(a);
        }
        setAttr("ltabs", ltabs);

		render("/WEB-INF/view/fore/y/y-demo.html");
	}
	
	/**
	 * 跳转到保存修改页 
	 */
	public void savep(){
		setAttr("row", getRow(YDemoModel.class));
		render("/WEB-INF/view/manage/y/y-demo-input.html");
	}
	
	/**
	 * 保存或修改
	 */
	public void save(){
		String validate = validate();
		if(validate == null){
			renderJson(save(YDemoModel.class));
		}else{
			renderJson(QJsonUtil.error(validate));
		}
	}
	
	/**
	 * 删除一条或多条
	 */
	public void del(){
		renderJson(del(YDemoModel.class));
	}
	
}
